<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:if test="${command.loanBill.billType=='IN'}">
	<c:set var="nameStr" value="借入" />
	<c:set var="costName" value="收款" />
</c:if>
<c:if test="${command.loanBill.billType=='OUT'}">
	<c:set var="nameStr" value="借出" />
	<c:set var="costName" value="付款" />
</c:if>
<c:set var="pageTopTitle" value="资金${nameStr}单" />
<c:set var="pageTitle" value="${pageTopTitle}" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillEdit.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function doSave(contFlag){
		document.getElementById("buttonDiv").style.display="none";
		document.getElementById("waitDiv").style.display="";
		document.getElementById("continue_flag").value=contFlag;
		<c:if test="${currentUser.user.userType==1 || command.loanBill.billType=='IN' && fn:indexOf(currentUser.privs,';LOAN_IN_EXAM;')!=-1 || command.loanBill.billType=='OUT' && fn:indexOf(currentUser.privs,';LOAN_OUT_EXAM;')!=-1}">
			ShowConfirm('确认框','是否同时审核？',340,80,"doSaveExt('"+contFlag+"')");
		</c:if>
		<c:if test="${!(currentUser.user.userType==1 || command.loanBill.billType=='IN' && fn:indexOf(currentUser.privs,';LOAN_IN_EXAM;')!=-1 || command.loanBill.billType=='OUT' && fn:indexOf(currentUser.privs,';LOAN_OUT_EXAM;')!=-1)}">
			<c:if test="${id==null || id==''}">
				if(contFlag!='NEW' && contFlag!='COPY'){
					ShowConfirm('确认框','是否现在打印？',340,80,"doSavePrint()");
				}else{
					frm.submit();
				}
			</c:if>
			<c:if test="${id!=null && id!=''}">
				frm.submit();
			</c:if>
		</c:if>
	}
	function doSaveExt(contFlag){
		if(popRetVal!=null){
			document.getElementById("examine").value="1";
		}else{
			document.getElementById("examine").value="0";
		}
		<c:if test="${id==null || id==''}">
			if(contFlag!='NEW' && contFlag!='COPY'){
				ShowConfirm('确认框','是否现在打印？',340,80,"doSavePrint()");
			}else{
				frm.submit();
			}
		</c:if>
		<c:if test="${id!=null && id!=''}">
			frm.submit();
		</c:if>
	}
	function doSavePrint(){
		if(popRetVal!=null){
			if(window.opener){
				document.getElementById("print_flag").value="REDI";
			}else{
				document.getElementById("print_flag").value="NEW_WIN";
			}
		}
		frm.submit();
	}
	function doCancel(){
		if(window.opener){
			window.close();
		}else{
			var retVal="${retVal}";
			if(retVal!=""){
				parent.popRetVal=retVal;
			}
			parent.ClosePop();
		}
	}
	function selectStaffer(){
		var url="/base/StafferMainForSelect.ihtm";
		ShowIframe("选择员工",url,800,500,"selectStafferCallBack()",1024,420);
	}
	function selectStafferCallBack(){
		if(popRetVal!=null){
			var arr=popRetVal.split(";");
			document.getElementById("loanBill.managerId").value=arr[0];
			document.getElementById("loanBill.managerName").value=arr[1];
			
			if(document.getElementById("loanBill.rpName").value==""){
				document.getElementById("loanBill.rpName").value=arr[1];
			}
			var depObj=document.getElementById("loanBill.departmentId");
			for(var i=0;i<depObj.options.length;i++){
				if(arr[2]==depObj.options[i].value){
					depObj.options[i].selected=true;
					break;
				}
			}
		}
	}
	function doPrint(id){
		showWin(900,360,"/finance/LoanBillPrint.ihtm?id="+id);
	}
	function showMe(){
		showFormErrorMsg();
		document.getElementById("costStr").focus();
	}
	function doWinUnload(){
		var retVal='${retVal}';
		if(retVal!='' && !window.opener){
			parent.popRetVal=retVal;
		}
	}
</script>
</head>
<body scroll="no" onLoad="showMe();" onUnload="doWinUnload();">
<div class="Wrap">
	<form name="frm" method="post" enctype="multipart/form-data">
	<div class="Container">
		<div class="Contnet Paper">
			<c:if test="${command.loanBill.enabled=='N' || id!=null && id!='' && command.loanBill.examined=='Y'}">
				<c:set var="disabledStr" value="disabled='true'" />
			</c:if>
			<c:if test="${currentUser.user.userType!=1 && command.loanBill.billType=='IN' && fn:indexOf(currentUser.privs,';LOAN_IN;')==-1}">
				<c:set var="disabledStr" value="disabled='true'" />
			</c:if>
			<c:if test="${currentUser.user.userType!=1 && command.loanBill.billType=='OUT' && fn:indexOf(currentUser.privs,';LOAN_OUT;')==-1}">
				<c:set var="disabledStr" value="disabled='true'" />
			</c:if>
			
			<c:set var="codeReadOnlyStr" value="" />
  			<c:set var="codeReadOnlyClassStr" value="" />
			<c:if test="${command.codeRule.generateRule!='MANUAL'}">
      			<c:set var="codeReadOnlyStr" value="readonly='readonly'" />
				<c:set var="codeReadOnlyClassStr" value="disabled" />
      		</c:if>
      		
      		<c:set var="dateEdit" value="Y" /><!-- 是否可以编辑日期 -->
	    	<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_BILL_DATE;')!=-1}">
				<c:set var="dateEdit" value="N" />
			</c:if>
		
			<!-- 提示信息 -->
			<%@ include file="../inc/BillPageTop.jsp"%>
			
			<!--单 标题-->
			<br>
	        <table class="BillHeading" cellspacing="0" cellpadding="0">
	        	<tr>
		            <td width="301px;" rowspan="2" ><div class="CorpLogo"><img src="${enterpriseInfo.loginImage}" /></div></td>
		            <td width="301px;" rowspan="2" ><h1>${pageTopTitle}</h1></td>
		            <td width="301px;" class="tr vb codeTd"> 
		                <span class="MustInput">*</span>编号：
		                <spring:bind path="command.loanBill.billCode">
				    	<input type="text" class="tbBillCode TextBox ${codeReadOnlyClassStr}" ${codeReadOnlyStr} maxlength="30" onKeyUp="goNextInput('loanDateStr');" id="${status.expression}" name="${status.expression}" value="${status.value}">
				    	<script language="javascript">
							setFormErrorMsg('<c:out value="${status.errorMessage}" />',1,'loanBill.billCode');
						</script>
			     		</spring:bind>
		            </td>
	        	</tr>
	        	<tr>
	            	<td class="tr" >
	            		<span id="calPosi"></span>
		            	<span class="MustInput">*</span>日期：
		            	<spring:bind path="command.loanDateStr">
		                    <input type="text" class="tbBillDate_sim TextBox <c:if test="${dateEdit=='N'}">readonly</c:if>" maxlength="15" onKeyUp="goNextInput('loanBill.rpName');" id="${status.expression}" name="${status.expression}" value="${status.value}" <c:if test="${dateEdit=='N'}">readonly="readonly"</c:if> />
		                    <c:if test="${dateEdit=='Y'}"><img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('loanDateStr'),'yyyy-mm-dd',document.getElementById('calPosi'));"></c:if>
		                    <script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',2,'loanDateStr');
						    </script>
		                </spring:bind>
	            	</td>
	        	</tr>
	        </table>

			<!-- 附加信息 -->
	        <div class="TopBottom_Border">
	        	<table class="BillElseInfo" cellspacing="0" cellpadding="0" style="position:relative;"><!-- ie6要在这里加position:relative下面的附件div才不会错位 -->
	        		<tr>
	            		<th width="84px"><span class="MustInput">*</span>借款人：</th>
	            		<td width="217px">
	            			<spring:bind path="command.loanBill.rpName">
							<input class="tbInfo_sim TextBox" type="text" maxLength="15" onKeyUp="goNextInput('costStr');" id="${status.expression}" name="${status.expression}" value="${status.value}">
					        <script language="javascript">
					          	setFormErrorMsg('<c:out value="${status.errorMessage}" />',3,'loanBill.rpName');
					        </script>
					        </spring:bind>
	            		</td>
	            		<th width="84px"><span class="MustInput">*</span>经办人：</th>
	            		<td width="217px">
	            			<spring:bind path="command.loanBill.managerName">
							<input class="tbInfo_sim TextBox readonly" type="text" id="${status.expression}" name="${status.expression}" value="${status.value}">
							</spring:bind>
							<img class="make-a" src="/images/make-a.gif" style="cursor:pointer;" onClick="selectStaffer();">
							<spring:bind path="command.loanBill.managerId">
							<input type="hidden" id="${status.expression}" name="${status.expression}" value="${status.value}">
					        <script language="javascript">
					          	setFormErrorMsg('<c:out value="${status.errorMessage}" />',4);
					        </script>
							</spring:bind>
	            		</td>
	            		<th width="84px"><span class="MustInput">*</span>部门：</th>
	            		<c:set var="depEditDisabledStr" value="${editDisabledStr}" />
			            <c:if test="${fn:indexOf(currentUser.privs,';NO_BILL_DEPA;')!=-1}">
			                <c:set var="depEditDisabledStr" value="disabled='disabled'" />
			            </c:if>
	            		<spring:bind path="command.loanBill.departmentId">
            			<td width="218px">
            				<select id="${status.expression}" name="${status.expression}" class="ddlInfo_sim" ${depEditDisabledStr} <c:if test="${depEditDisabledStr!=''}">style='background:#f6f6f6;'</c:if>>
                    			<option value="0">==请选择==</option>
                    			<commonTag:createSelectTree list="${departmentList}" emptyOption="0" defaultValue="${status.value}" />
                			</select>
                			<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',5);
						    </script>
            			</td>
            			</spring:bind>
	        		</tr>
	        		<tr>
	            		<th><span class="MustInput">*</span>${costName}账户：</th>
        				<spring:bind path="command.loanBill.bankAccountId">
        				<td>
        					<select id="${status.expression}" name="${status.expression}" class="ddlInfo_sim">
                				<c:if test="${id!=null && id!=''}"><option value="0">==请选择==</option></c:if>
                				<c:forEach var="item" items="${bankAccountList}">
                					<option value="${item.id}" <c:if test="${status.value==item.id}">selected</c:if>>${item.bankName}<c:if test="${item.accountName!=null && item.accountName!=''}">(${item.accountName})</c:if></option>
                				</c:forEach>
            				</select>
            				<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',7);
						    </script>
        				</td>
        				</spring:bind>
            			<th><span class="MustInput">*</span>${costName}金额：</th>
        				<spring:bind path="command.costStr">
        				<td>
        					<input type="text" class="tbInfo_sim TextBox" maxlength="10" onKeyUp="goNextInput('loanBill.mark');" name="${status.expression}" id="${status.expression}" value='${status.value}'>
        					<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',8,'costStr');
						    </script>
        				</td>
        				</spring:bind>
        				<th>&nbsp;</th>
	            		<td>&nbsp;</td>
        			</tr>
        			<tr>
        				<th>摘要：</th>
        				<spring:bind path="command.loanBill.mark">
        				<td colspan="5">
        					<textarea class="TextBox" name="${status.expression}" id="${status.expression}" style="width:764px;height:40px"><c:out value="${status.value}" /></textarea>
            				<script language="javascript">
						    	setFormErrorMsg('<c:out value="${status.errorMessage}" />',11,'loanBill.mark');
						    </script>
        				</td>
        				</spring:bind>
        			</tr>
        			<tr>
        				<th>上传凭证：</th>
        				<td colspan="5">
        					<div style="position:relative; width:480px; height:28px; overflow:hidden; float:left;">
        						<input type="text" class="TextBox readonly" readonly="readonly" style="width:470px;" name="tmp_att" id="tmp_att">
        					</div>
        					<div style="position:relative;width:40px;height:28px;overflow:hidden;float:left;"> 
								<div style="position:absolute;top:0px;left:0px;width:100%;height:100%;">
									<img class="make-a" src="/images/make-a.gif">
								</div> 
								<input type="file" name="attach_file" id="attach_file" onchange="document.getElementById('tmp_att').value=this.value" style="position:absolute;top:0px;right:0px;cursor:pointer;opacity:0;filter:alpha(opacity:0);z-index:99;"> 
							</div>
							<c:if test="${command.loanBill.attachFile!=null && command.loanBill.attachFile!=''}">
								<div><a href="${command.loanBill.attachFile}" target="_blank">${command.attachFileName}</a></div>
							</c:if>
							<spring:bind path="command.loanBill.attachFile">
						    	<script language="javascript">
						        	setFormErrorMsg('<c:out value="${status.errorMessage}" />',12);
						    	</script>
					      	</spring:bind>
        				</td>
        			</tr>
	        	</table>
	        </div>

			<br>
			<div class="BillNotes">
                <span>开单人：${command.loanBill.createrName} <c:if test="${command.loanBill.createTime!=null}"><fmt:formatDate value="${command.loanBill.createTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></span>
        		<span>审核人：<c:if test="${command.loanBill.examinerId!=0}">${command.loanBill.examinerName} <c:if test="${command.loanBill.examineTime!=null}"><fmt:formatDate value="${command.loanBill.examineTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></c:if></span>
				<span>单据帐套：${command.tallySetName}</span>
				<spring:bind path="command.loanBill.tallySetId">
					<script language="javascript">
						setFormErrorMsg('<c:out value="${status.errorMessage}" />',1);
					</script>
				</spring:bind>
			</div>
	        
		</div>
		
		<!-- 底栏按钮 -->
		<div class="Footer">
			<div id="buttonDiv">
				<c:if test="${id!=null && id!=''}">
					<input type="button" class="buttom-a" value=" 打 印 " onClick="doPrint(${id});" <c:if test="${command.loanBill.enabled=='N'}">disabled='true'</c:if>>
				</c:if>
				<input type="button" class="buttom-a" value=" 保 存 " onClick="doSave('');" ${disabledStr}>
				<c:if test="${id==null || id==''}">
					<input type="button" class="buttom-a" value="保存并新增" onClick="doSave('NEW');" ${disabledStr}>
					<input type="button" class="buttom-a" value="保存并复制" onClick="doSave('COPY');" ${disabledStr}>
				</c:if>
				<input type="button" class="buttom-a" value=" 取 消 " onClick="doCancel();">
				<input type="hidden" name="continue_flag" id="continue_flag" value="">
				<input type="hidden" id="examine" name="examine" value="0">
				<input type="hidden" name="print_flag" id="print_flag" value="">
			</div>
			<div id="waitDiv" style="display:none">
    			<span>请稍候...</span>
			</div>
		</div>
		
	</div>
	</form>
</div>
</body>
</html>
